package util;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

import androidx.annotation.Nullable;

public class MyDatabaseHelper extends SQLiteOpenHelper {

    //创建user表sql语句，只在onCreate方法中调用了
    public static final String CREAT_userTable = "create table user" +
            "(" +
            "name text not null primary key," +
            "password text not null," +
            "photoNumber TEXT UNIQUE NOT NULL" +
            ");";
    public static final String CREAT_phoneNumber = "create table phoneNumber" +
            "(" +
            "name text not null primary key," +
            "phoneNumber TEXT UNIQUE NOT NULL" +
            ");";


    private final Context mContext;

    public MyDatabaseHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        mContext = context;
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(CREAT_userTable);
        sqLiteDatabase.execSQL(CREAT_phoneNumber);
        Toast.makeText(mContext, "数据库创建成功", Toast.LENGTH_LONG).show();
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }

}

